package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.ScoreDAO;
import com.zerosky.crm.po.Score;
import com.zerosky.crm.service.ScoreService;
import com.zerosky.crm.util.PageInfo;

@Service(value = "scoreService")
public class ScoreServiceImpl implements ScoreService {
	@Autowired
	private ScoreDAO ScoreDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Score> getScoreAllList(Map map) {
		return ScoreDao.getScoreAllList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Score> getScorePageInfoList(Map map) {
		int begin = (((int) map.get("page") - 1) * (int) map.get("limit"));
		int pageSize = (int) map.get("limit");
		PageInfo<Score> page = new PageInfo<Score>();
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Score> list = ScoreDao.getScoreAllList(map);
		page.setList(list);

		Integer count = ScoreDao.countScore(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Score getScoreById(String ScoreId) {
		return ScoreDao.getScoreById(ScoreId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int addScore(Score Score) {
		return ScoreDao.addScore(Score);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void updateScore(Score Score) {
		ScoreDao.updateScore(Score);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteScoreById(String ScoreId) {
		ScoreDao.deleteScoreById(ScoreId);
	}
}
